package com.cnseedlingscloud.draw.prize.dao;

import com.cnseedlingscloud.draw.prize.entity.TurntableDraw;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TurntableDrawDao {
    @Results(id = "turntableDrawMap", value = {
            @Result(property = "id", column = "id", id = true),
            @Result(property = "drawName", column = "draw_name"),
            @Result(property = "prizeName", column = "prize_name"),
            @Result(property = "weight", column = "weight"),
            @Result(property = "prizeNum", column = "prize_num") })

    @Select("select * from turntable_draw where id= #{id}")
    TurntableDraw findById(Long id);

    @Insert("insert into turntable_draw(draw_name,prize_name,weight,prize_num)values(#{drawName},#{prizeName},#{weight},#{prizeNum})")
    @Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
    Integer save(TurntableDraw turntableDraw);

    @ResultMap("turntableDrawMap")
    @Select("select * from turntable_draw ORDER BY id ")
    List<TurntableDraw> findAll();

    @Delete("delete from turntable_draw where id=#{id}")
    Integer delete(Long id);

    @Update("update turntable_draw set draw_name=#{drawName},prize_name=#{prizeName},prize_num=#{prizeNum} where id=#{id}")
    Integer update(TurntableDraw turntableDraw);
}
